
*******************************************************************************
****						Appendix Table G.11 - REGRESSION OF TOTAL TOLL 
****	ON TIME DIFFERENTIALS: RELIABILITY MOMENTS AND WINDOW ROBUSTNESS	
*******************************************************************************

use ".\data\clean\I10W_laneuse_dataset_15nov14_wcensus", clear

merge m:1 date hour using ".\data\clean\HV_ML_reliab_30days.dta", keep(1 3) nogen 

gen reliabilityML2550=dist/p25_speedML-dist/p50_speedML
gen reliabilityHV2550=dist/p25_speedHV-dist/p50_speedHV
gen reliability_diff2550=reliabilityML2550-reliabilityHV2550

gen reliabilityML2050=dist/p20_speedML-dist/p50_speedML
gen reliabilityHV2050=dist/p20_speedHV-dist/p50_speedHV
gen reliability_diff2050=reliabilityML2050-reliabilityHV2050

gen reliabilityML1050=dist/p10_speedML-dist/p50_speedML
gen reliabilityHV1050=dist/p10_speedHV-dist/p50_speedHV
gen reliability_diff1050=reliabilityML1050-reliabilityHV1050

gen reliability_sd=sd_speedML-sd_speedHV


replace reliability_diff2550=0 if reliability_diff2550<0
replace reliability_diff2050=0 if reliability_diff2050<0
replace reliability_diff1050=0 if reliability_diff1050<0
replace reliability_sd=0 if reliability_sd<0

*WTP calculation
gen TT_dif_hr=dist/MLspeed-dist/ELspeed
gen WTP2=charged_toll/TT_dif_hr
drop if ELspeed==.
drop if TT_dif_hr==.
drop if holiday==1
la var TT_dif_hr "Time in Hours"
la var reliability_diff2550 "Reliability - 75-50 qtile"
la var reliability_diff2050 "Reliability - 80-50 qtile"
la var reliability_diff1050 "Reliability - 90-50 qtile"
la var reliability_sd "Reliability - std. dev."



drop if dow==0|dow==6
keep if acct_type=="PRIVATE"&occupancy~="HOV-3"
keep if hour>4 & hour<9
g exittime=hh(exit_time)+mm(exit_time)/60+ss(exit_time)/(60*60)
egen exittimemean=mean(exittime), by(acct_no)
g exittimediff=exittime-exittimemean
g TT_dif_hr2 =TT_dif_hr^2
est sto clear
reg charged_toll TT_dif_hr reliability_diff2550 if TT_dif_hr>0, cluster(rt_id)
est sto a0
*estat ic

reg charged_toll TT_dif_hr reliability_diff2050 if TT_dif_hr>0, cluster(rt_id)
est sto a1
*estat ic

reg charged_toll TT_dif_hr reliability_diff1050 if TT_dif_hr>0, cluster(rt_id)
est sto a2
*estat ic

reg charged_toll TT_dif_hr reliability_sd if TT_dif_hr>0, cluster(rt_id)
est sto a3
*estat ic

esttab  a0 a1 a2 a3   using ".\results\appendix\tabs\ATG11pa.csv", replace  ///
	cells(b(star fmt(%9.2f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) stats(N r2 ll aic bic,fmt(%9.0f %9.2f %12.0f) labels(Observations R-Squared Log-Likelihood AIC BIC)) ///
	 order( _cons TT_dif_hr reliability_diff2550 reliability_diff2050 reliability_diff1050 reliability_diff_sd) label  nonumbers nodepvars
	est sto clear
local nlist 15 30 60 90 120
local ii=1
local alist
forval d=1/5{
quietly{
	use ".\data\clean\I10W_laneuse_dataset_15nov14_wcensus", clear
	local dd: word `d' of `nlist'
	merge m:1 date hour using ".\data\clean\\HV_ML_reliab_`dd'days.dta", keep(1 3) nogen 

	gen reliabilityML=dist/p20_speedML-dist/p50_speedML
	gen reliabilityHV=dist/p20_speedHV-dist/p50_speedHV
	gen reliability_diff=reliabilityML-reliabilityHV

	*WTP calculation
	gen TT_dif_hr=dist/MLspeed-dist/ELspeed
	gen WTP2=charged_toll/TT_dif_hr
	drop if ELspeed==.
	drop if TT_dif_hr==.
	drop if holiday==1
	la var TT_dif_hr "Time in Hours"
	la var reliability_diff "Reliability"
	drop if dow==0|dow==6
	keep if acct_type=="PRIVATE"&occupancy~="HOV-3"
	keep if hour>4 & hour<9
	replace reliability_diff=0 if reliability_diff<0
	g exittime=hh(exit_time)+mm(exit_time)/60+ss(exit_time)/(60*60)
	egen exittimemean=mean(exittime), by(acct_no)
	g exittimediff=exittime-exittimemean
	g TT_dif_hr2 =TT_dif_hr^2
	egen id=group(date rt_id)
	egen tid=group(date hour rt_id)
	}
	qui reg charged_toll TT_dif_hr reliability_diff if TT_dif_hr>0,  cluster(rt_id)
	estat ic
	est sto a`ii'
	local alist "`alist' a`ii'"
	local ii=`ii'+1

	}
	esttab  `alist' using ".\results\appendix\tabs\ATG11pb.csv", replace  ///
		cells(b(star fmt(%9.2f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) stats(N r2 aic bic ll,fmt(%9.2f) labels(Observations R-Squared AIC BIC Log-Likelihood)) label ///
		 order(_cons TT_dif_hr reliability_diff) keep(TT_dif_hr _cons reliability_diff)  nonumbers nodepvars

		
		
preserve
insheet using ".\results\appendix\tabs\ATG11pb.csv", clear comma
tempfile temp
save `temp'
insheet using ".\results\appendix\tabs\ATG11pa.csv", clear comma
local N=_N+2
set obs `N'
append using `temp'
export excel ".\results\appendix\AppendixFigsTabs.xlsx", sheetmodify sheet("Appendix Table G.11")
restore

